package info.woodcock.security;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {

    //using annotation to marked method
    @Pointcut("@annotation(info.woodcock.security.annotation.Log)")
    public void pointcut(){
    }

    /* ProceedingJoinPoint类型是个关键 */
    @Around("pointcut()")
    public void around(ProceedingJoinPoint joinPoint){
        long startTime = System.currentTimeMillis();
        try {
            joinPoint.proceed();
        }catch (Throwable e){

        }finally {
            long endTime = System.currentTimeMillis();
            System.out.println("elapsed time: " + (endTime - startTime));
        }
    }
}
